package com.camps.sdk.encrypt;

import com.camps.sdk.common.ExceptionCode;
import com.camps.sdk.entity.DeviceLinkAddress;
import com.camps.sdk.exception.BaseException;

/**
 * @Author ldaoliang
 * @Date create in 10:11 2021/9/1
 * @Description
 */
public class DefaultIpAndPortCommand implements BuildCommand {
    @Override
    public String splicingParameters(String imei,Object params) {
        DeviceLinkAddress deviceLinkAddress = null;
        try{
            deviceLinkAddress = (DeviceLinkAddress)params;
        }catch (Exception e){
            throw new BaseException(ExceptionCode.PARAMETER_ERROR);
        }
        String ip = deviceLinkAddress.getIp();
        int port = deviceLinkAddress.getPort();
        int retryTimes = deviceLinkAddress.getRetryTimes();
        String commandNumber = deviceLinkAddress.getCommandNumber();
        // 构建指令
        StringBuilder sb = new StringBuilder("*WT,");
        sb = sb.append(imei).append(",S23,").append(commandNumber).append(",").
                append(ip.replaceAll(".",",")).append(port).append(retryTimes);
        return sb.toString();
    }
}
